|
|
|
|
|
|
|
7. Use the Package and Deployment Wizard or another utility to build a distributable version of the control that includes all the supporting files. |
|
|
|
|
|
|
|
|
Building an ActiveX control in Visual Basic can be as easy or difficult as you choose. The level of difficulty depends on whether you use existing controls in your design, how sophisticated the interface will be, and of course, how much code you have to write to make it work. In any case, you can go about building an ActiveX control in three basic ways: |
|
|
|
|
|
|
|
|
Assemble the control from existing controls. This approach is also known as building a control from constituent controls. It is the easiest way to build an ActiveX control because you are just bringing existing controls together. For example, you can package a combo box and a text box together and write minimal code that causes them to interact in the desired manner. |
|
|
|
|
|
|
|
|
Enhance an existing control. You can use an existing control as a starting point for your own creative efforts by modifying the control properties. For example, you can take a text box and add a custom property called TextCaps that causes the text to always be displayed in capital letters. This approach is a good way to get the exact functionality that you need in a control. |
|
|
|
|
|
|
|
|
Create a user-drawn control. You can draw the interface yourself with graphics methods, creating a totally original control that does not include any existing controls. Drawing your own control requires a little more work than the other two strategies but can be done to provide an original or different user interface. |
|
|
|
|
|
|
|
|
This chapter introduces you to the world of creating ActiveX controls. You'll learn about each of the preceding development strategies through sample projects, as well as learn about distributing and compiling the finished control. Chapter 15, "Extending ActiveX Controls," looks at some of the more advanced topics relating to ActiveX controls. |
|
|
|
|
|
|
|
|
Creating an ActiveX Control |
|
|
|
|
|
|
|
|
Assembling an ActiveX control from other existing controls provides many advantages. First, when you add an existing control to your new custom control, you get the existing control's complete functionalityan important consideration when you think about how many event procedures, methods, and properties are supported by an average control. Second, combining a number of controls into one allows them to be treated as a single unit, which may make things easier from an application architecture standpoint; this approach also allows them to be drawn on the form all at once. An additional advantage is that the users can easily understand a control made up of controls they already know. |
|
|
|
|
|
|
|
|
Starting the Address Control Project |
|
|
|
|
|
|
|
|
Now that you have some background information on ActiveX controls, you can get started by creating your first ActiveX control. The control that you'll build in this section is the AddressCtl control, which is simply text box fields that allow the users to enter their names and addresses. |
|
|
|
|
|